//
//  UIBarbuttonItem + Extension.swift
//  SinaWeiBo
//
//  Created by dengchen on 15/11/19.
//  Copyright © 2015年 name. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    convenience init(image:String?,target:AnyObject?,action:String?) {
        let btn = UIButton()
        
        if image != nil {
            btn.setImage(UIImage(named: image!), forState: .Normal)
            btn.setImage(UIImage(named: image! + "_highlighted"), forState: .Highlighted)
        }
        
        if action != nil && target != nil {
            btn.addTarget(target, action: Selector(action!), forControlEvents: UIControlEvents.TouchUpInside)
        }
        
        btn.sizeToFit()
        
        self.init(customView:btn)
    }

}